package com.ruoyi.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wms.domain.WmsInventoryAllocation;
import com.ruoyi.wms.service.IWmsInventoryAllocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;

/**
 * 库存分配Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Api(tags = "库存分配管理")
@RestController
@RequestMapping("/wms/inventory/allocation")
public class WmsInventoryAllocationController extends BaseController
{
    @Autowired
    private IWmsInventoryAllocationService wmsInventoryAllocationService;

    /**
     * 查询库存分配列表
     */
    @ApiOperation("查询库存分配列表")
    @PreAuthorize("@ss.hasPermi('wms:inventory:allocation:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsInventoryAllocation wmsInventoryAllocation)
    {
        startPage();
        List<WmsInventoryAllocation> list = wmsInventoryAllocationService.selectWmsInventoryAllocationList(wmsInventoryAllocation);
        return getDataTable(list);
    }

    /**
     * 根据明细ID查询分配列表
     */
    @ApiOperation("根据明细ID查询分配列表")
    @ApiImplicitParam(name = "detailId", value = "出库单明细ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:inventory:allocation:list')")
    @GetMapping("/detail/{detailId}")
    public AjaxResult listByDetailId(@PathVariable("detailId") Long detailId)
    {
        List<WmsInventoryAllocation> list = wmsInventoryAllocationService.selectWmsInventoryAllocationByDetailId(detailId);
        return success(list);
    }

    /**
     * 根据出库单ID查询分配列表
     */
    @ApiOperation("根据出库单ID查询分配列表")
    @ApiImplicitParam(name = "orderId", value = "出库单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:inventory:allocation:list')")
    @GetMapping("/order/{orderId}")
    public AjaxResult listByOrderId(@PathVariable("orderId") Long orderId)
    {
        List<WmsInventoryAllocation> list = wmsInventoryAllocationService.selectWmsInventoryAllocationByOrderId(orderId);
        return success(list);
    }

    /**
     * 导出库存分配列表
     */
    @ApiOperation("导出库存分配列表")
    @PreAuthorize("@ss.hasPermi('wms:inventory:allocation:export')")
    @Log(title = "库存分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsInventoryAllocation wmsInventoryAllocation)
    {
        List<WmsInventoryAllocation> list = wmsInventoryAllocationService.selectWmsInventoryAllocationList(wmsInventoryAllocation);
        ExcelUtil<WmsInventoryAllocation> util = new ExcelUtil<WmsInventoryAllocation>(WmsInventoryAllocation.class);
        util.exportExcel(response, list, "库存分配数据");
    }

    /**
     * 获取库存分配详细信息
     */
    @ApiOperation("获取库存分配详细信息")
    @ApiImplicitParam(name = "allocationId", value = "库存分配ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:inventory:allocation:query')")
    @GetMapping(value = "/{allocationId}")
    public AjaxResult getInfo(@PathVariable("allocationId") Long allocationId)
    {
        return success(wmsInventoryAllocationService.selectWmsInventoryAllocationById(allocationId));
    }

    /**
     * 新增库存分配
     */
    @ApiOperation("新增库存分配")
    @PreAuthorize("@ss.hasPermi('wms:inventory:allocation:add')")
    @Log(title = "库存分配", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsInventoryAllocation wmsInventoryAllocation)
    {
        return toAjax(wmsInventoryAllocationService.insertWmsInventoryAllocation(wmsInventoryAllocation));
    }

    /**
     * 修改库存分配
     */
    @ApiOperation("修改库存分配")
    @PreAuthorize("@ss.hasPermi('wms:inventory:allocation:edit')")
    @Log(title = "库存分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsInventoryAllocation wmsInventoryAllocation)
    {
        return toAjax(wmsInventoryAllocationService.updateWmsInventoryAllocation(wmsInventoryAllocation));
    }

    /**
     * 删除库存分配
     */
    @ApiOperation("删除库存分配")
    @ApiImplicitParam(name = "allocationIds", value = "库存分配ID数组", required = true, dataType = "Long[]", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:inventory:allocation:remove')")
    @Log(title = "库存分配", businessType = BusinessType.DELETE)
    @DeleteMapping("/{allocationIds}")
    public AjaxResult remove(@PathVariable Long[] allocationIds)
    {
        return toAjax(wmsInventoryAllocationService.deleteWmsInventoryAllocationByIds(allocationIds));
    }
}